package com.ruoyi.framework.config;

import me.chanjar.weixin.common.service.WxOAuth2Service;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpUserService;
import me.chanjar.weixin.mp.api.impl.WxMpOAuth2ServiceImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.api.impl.WxMpUserServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@ConditionalOnClass(WxMpNewServiceConfig.class)
public class WxMpNewServiceConfig {

//    @Resource
//    private WxProperties properties;

    private static final String APP_ID = "wx628300e827d81d58";
    private static final String MP_SECRET = "ae2661e2a8782665d9bf2e96c5b7e825";
    private static final String TOKEN = "N5gADM2U7DMwICDN4YFTMA1EnIx114";
    private static final String AES_KEY = "awp9RkzqG6Dv606UtlWGN6jlUJhlp2hYtxkeySovKWQ";



    @Bean
    public WxMpDefaultConfigImpl wxMpDefaultNewConfigImpl() {
        WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
        config.setAppId(APP_ID); // 设置微信公众号的appid
        config.setSecret(MP_SECRET); // 设置微信公众号的app corpSecret
        config.setToken(TOKEN); // 设置微信公众号的token
        config.setAesKey(AES_KEY); // 设置微信公众号的EncodingAESKey
        return config;
    }

    @Bean
    @ConditionalOnMissingBean
    public WxMpService wxNewMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpDefaultNewConfigImpl());
        return wxMpService;
    }

    @Bean
    @ConditionalOnMissingBean
    public WxMpUserService wxNewMpUserService() {
        return new WxMpUserServiceImpl(this.wxNewMpService());
    }

    @Bean
    @ConditionalOnMissingBean
    public WxOAuth2Service wxNewOAuth2Service() {
        return new WxMpOAuth2ServiceImpl(this.wxNewMpService());
    }

}
